<template>
    <uni-popup ref="weChatPopup" :mask-click="true" @change="popupChange">
        <view class="wechat-code-view">
            <text class="wechat-code-view-title">{{ title }}</text>
            <image class="wechat-code-view-img" :src="imgSrc" :show-menu-by-longpress="true"></image>
            <uni-icons @tap="closePopup" class="popup-close" type="close" size="80rpx" color="#fff"></uni-icons>
        </view>
    </uni-popup>
</template>

<script setup>
import { ref } from 'vue';
import { getImgOssUrl } from '@/commons/utils';

const props = defineProps({
    title: {
        type: String,
        default: '加官方企微好友，接收最新信息'
    },
    imgSrc: {
        type: String,
        default: getImgOssUrl('/ui-prod-2.0.0/errorImg.png')
    }
});

const emit = defineEmits(['closed']);

const weChatPopup = ref();

const openPopup = () => {
    weChatPopup?.value?.open('center');
};

const closePopup = () => {
    weChatPopup?.value?.close();
};

const popupChange = ({ show }) => {
    if (!show) {
        emit('closed');
    }
};

defineExpose({
    openPopup
});
</script>

<style lang="scss" scoped src="./index.scss"></style>
